package ar.com.mooral.activities;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import ar.com.mooral.crohn.application.CrohnContext;
import ar.com.mooral.data.Consultations;
import ar.com.mooral.data.GeneralStatus;
import ar.com.mooral.data.Result;
import ar.com.mooral.pojo.ConsultationPojo;
import ar.com.mooral.pojo.GeneralStatusPojo;


public class DoctorConsultationNew extends CrohnActivity {
    
	private EditText txtDoctorConsultationConsultation;
	
	private ConsultationPojo pojo;

	protected Consultations consultations;
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.doctor_consultation_new);
        
        if (!CrohnContext.isPojoLoaded()) {
        	ConsultationPojo newPojo = new ConsultationPojo();
			newPojo.setDate(CrohnContext.getDateTimeNow("dd/MM/yyyy"));
			CrohnContext.setPojo(newPojo);
		}
		pojo = (ConsultationPojo) CrohnContext.getPojo();
		
		consultations = new Consultations(this);

		txtDoctorConsultationConsultation = (EditText)findViewById(R.id.txtDoctorConsultationConsultation);
        txtDoctorConsultationConsultation.setText(pojo.getName());

        // CANCEL
    	Button btnDoctorConsultationNewCancel = (Button) findViewById(R.id.btnDoctorConsultationNewCancel);
    	btnDoctorConsultationNewCancel.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
		    	finish();
		    }
		});
    	        
        
        // GUARDAR
    	Button btnDoctorConsultationNewSave = (Button) findViewById(R.id.btnDoctorConsultationNewSave);
    	btnDoctorConsultationNewSave.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {

		    	pojo.setName(txtDoctorConsultationConsultation.getText().toString());

		    	Result r = consultations.save(pojo);
		    	if (r.hasError()) {
		        	showMessage(r);
		        } else {
			    	finish();
		        }

		    }
		});		
        
    }
}
